<template>
  <div class="left-neighbor">
    <!-- 智能掘进 -->
    <data-box
      :bg="box_header"
      he="3.0625rem"
      wd="29.375rem"
      class="driving-box"
      title="智能掘进"
    >
      <template slot="content">
        <div class="progress">
          <div class="progress-left">
            <ProgressBar
              wd="17.5rem"
              he="0.3125rem"
              percent="94%"
              theme="cyan"
              title="今日进尺"
              num="37.8"
              unit="米"
              bg="linear-gradient(to right,#2753A8, #00AFFF,#16FFFF)"
            />
            <ProgressBar
              style="margin-top: 0.9375rem"
              wd="17.5rem"
              he="0.3125rem"
              percent="21%"
              theme="#57ffaa"
              title="月累计"
              num="268.2"
              unit="米"
              bg="linear-gradient(to right,#35BD9C, #2BFFC8,#12FDFC)"
            />
          </div>
          <div class="progress-right">
            <div class="effect-img">
              <span class="effect-num">0.15</span>
            </div>
            <span class="effect-text">掘进工效 (米/工)</span>
          </div>
        </div>

        <div class="recent" style="margin-top: 1.3125rem">
          <SubTitle title="近7天全矿进尺趋势分析" wd="100%" he="1.5rem" />
          <!--智能采煤图表 -->
          <div class="coal-mining-chart">
            <LineChart
              :showLegend="true"
              :chart-data="mineralDeepChartData"
              :area="mineralDeepChartOption.area"
              :unit="mineralDeepChartOption.unit"
              :color="mineralDeepChartOption.color"
              :text="['近7天全矿进尺趋势分析']"
            />
          </div>
        </div>
      </template>
    </data-box>

    <!-- 智能优选 -->
    <data-box
      :bg="box_header"
      he="3.0625rem"
      wd="29.375rem"
      class="optimiztion-box"
      title="智能优选"
      style="margin-top: 0.875rem"
    >
      <template #tab>
        <div class="tab">
          <span
            v-for="t in tab"
            :key="t"
            class="tab-item"
            :class="{ active: curTab === t }"
            @click="changeTab(t)"
          >
            {{ t }}
          </span>
        </div>
      </template>
      <template slot="content">
        <div class="data-display">
          <div class="current-date">
            <span class="dot"></span>
            <span class="title">今日优选</span>
          </div>
          <div class="line"></div>
          <div class="data">
            <span class="num">11097</span>
            <span class="unit">吨</span>
          </div>
        </div>
        <div class="chart-box" style="margin-top: 2.375rem; height: 7.875rem">
          <PieChart3D
            class="chart"
            :option-data="day30List"
            :index="0"
            :change="true"
            :isActive="true"
            text="煤流"
          />
          <Legend
            style="height: 5.75rem"
            class="legend"
            shape="rect"
            wd="0.625rem"
            he="0.3125rem"
            unit="吨"
            itemWidth="100%"
            itemHeight="1.5rem"
            :legend="legend"
          />
        </div>
      </template>
    </data-box>
  </div>
</template>

<script>
const orderKeys = ['煤流', '环境', '排水'];
import PieChart3D from '@/components/chart/cockpit/PieChart3D.vue';
import LineChart from '@/components/chart/cockpit/LineChart';
import ProgressBar from '../lib/progressBar.vue';
import DataBox from '../lib/dataBox.vue';
import SubTitle from '../lib/subTitle.vue';
import Legend from '@/components/chart/cockpit/Legend.vue';

export default {
  name: 'DafosiControlWebLeftNeighbor',
  components: { DataBox, ProgressBar, SubTitle, LineChart, PieChart3D, Legend },

  data() {
    return {
      box_header: require('../../../assets/img/decisionAnalysis/box_header.png'),
      tab: ['日', '月', '年'],
      curTab: '日',
      mineralDeepChartOption: {
        color: ['#00fdff', '#a2b9fd'],
        area: true,
        unit: '米'
      },
      mineralDeepChartData: [
        { x: '12-01', y: 75, s: '计划进尺' },
        { x: '12-02', y: 30, s: '计划进尺' },
        { x: '12-03', y: 60, s: '计划进尺' },
        { x: '12-01', y: 37, s: '完成进尺' },
        { x: '12-02', y: 79, s: '完成进尺' },
        { x: '12-03', y: 42, s: '完成进尺' }
      ],
      dayList: [
        {
          alarmCount: 24,
          level1: 'COAL_FLOW',
          level1Desc: '煤流'
        },
        {
          alarmCount: 13,
          level1: 'ENVIRONMENT',
          level1Desc: '环境'
        },
        {
          alarmCount: 10,
          level1: 'WATER_DRAIN',
          level1Desc: '排水'
        }
      ],
      legend: [
        {
          name: '煤流',
          value: 24,
          color: '#1460f3'
        },
        {
          name: '环境',
          value: 13,
          color: '#35f4bc'
        },
        {
          name: '排水',
          value: 10,
          color: '#Fedb80'
        }
      ],
      color3D: ['#1460f3', '#35f4bc', '#Fedb80']
    };
  },

  computed: {
    day30List() {
      const day30List = this.formatChartData(orderKeys, this.dayList);
      return day30List.map((item, index) => {
        return {
          x: item.x,
          y: item.y,
          itemStyle: {
            color: this.color3D[index]
          }
        };
      });
    }
  },

  mounted() {},

  methods: {
    changeTab(val) {
      this.curTab = val;
    },
    // 调整图表数据格式，以及数据元素的排列顺序
    formatChartData(orderKeys, origin) {
      return orderKeys.map((orderKey) => {
        for (const item of origin) {
          if (orderKey === item.level1Desc) {
            return {
              x: item.level1Desc,
              y: item.alarmCount
            };
          }
        }
        return {
          x: orderKey,
          y: 0
        };
      });
    }
  }
};
</script>

<style lang="scss" scoped>
::v-deep .data-box-content {
  // margin-left: 0.25rem;
}
.data-box {
  .tab {
    @include date-tab();
  }
}

// 智能掘进
.driving-box {
  .progress {
    display: flex !important;
    justify-content: space-between;
    &-right {
      display: flex;
      flex-direction: column;
      // justify-content: center;
      align-items: center;
      .effect-img {
        width: 6.6856rem;
        height: 3.7225rem;
        background: url("../../../assets/img/decisionAnalysis/effect_img.png")
          no-repeat;
        position: relative;
      }
      .effect-num {
        font-size: 1.5rem;
        font-family: Agency FB, Agency FB-Bold;
        font-weight: 700;
        line-height: 1.5rem;
        letter-spacing: 0.15rem;
        line-height: 1;
        position: absolute;
        left: 50%;
        top: 15%;
        transform: translate(-50%, -50%);
      }

      .effect-text {
        margin-top: 0.6525rem;
        height: 0.75rem;
        font-size: 0.75rem;
        line-height: 1;
      }
    }
  }
  .recent {
    .coal-mining-chart {
      width: 100%;
      height: 7.125rem;
      margin-top: 0.625rem;
    }
  }
}
// 智能优选
.optimiztion-box {
  .data-display {
    height: 2.5625rem;
    display: flex;
    background-color: #11243d;
    align-items: center;
    .current-date {
      .dot {
        display: inline-block;
        width: 0.375rem;
        height: 0.375rem;
        line-height: 1;
        border-radius: 100%;
        background-color: $green;
        margin-left: 1.875rem;
      }
      .title {
        display: inline-block;
        font-size: 0.875rem;
        height: 0.875rem;
        line-height: 1;
        font-family: PingFang SC, PingFang SC-Regular;
        margin-left: 0.8125rem;
      }
    }
    .line {
      display: inline-block;
      width: 13.625rem;
      height: 0.0625rem;
      border: 1px dashed #3e4d62;
      background-color: #23344c;
      margin: 0rem 0.875rem;
      box-sizing: border-box;
      margin-top: 0.1875rem;
    }
    .data {
      .num {
        display: inline-block;
        font-size: 1.5rem;
        height: 1.5rem;
        line-height: 1;
        font-family: Agency FB, Agency FB-Regular;
        color: #00fdff;
      }
      .unit {
        display: inline-block;
        font-size: 0.75rem;
        height: 0.75rem;
        line-height: 1;
        font-family: PingFang SC, PingFang SC-Medium;
        margin-left: 0.25rem;
      }
    }
  }
  .chart-box {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    .chart {
      width: 13.0394rem;
    }
    .legend {
      width: 11.375rem;
      padding-right: 0.5rem;
      margin-left: 0.25rem;
      overflow-y: auto;
    }
  }
}
</style>
